package diancan.pojo;
import java.util.Scanner;
public class DianCan extends Father {
    public void p(){
        Menu menu1 = new Menu(1,"红烧肉",25.0,0);
        Menu menu2 = new Menu(2,"鱼香肉丝",40.0,0);
        Menu menu3 = new Menu(3,"肉末茄子",100.0,0);

        /*创建菜单类型的数组*/
        Menu menu[] = new Menu[3];
        menu[0]=menu1;
        menu[1]=menu2;
        menu[2]=menu3;

        //订单信息数组对象
        CIMenus clMenus = new CIMenus();


        Dfoot[] hu=clMenus.getDfNum();

        //点赞对象
        GoodLike goodLike =new GoodLike();


        System.out.println("欢迎使用K38订餐系统");

        Scanner scanner = new Scanner(System.in);

        int whinum=0;
        do {
            super.print();
            int num=scanner.nextInt();
            switch (num){
                case 1:
                    Dfoot dfoot =new Dfoot(); //实例化点餐人模块的对象
                    System.out.println("*****我要订餐*****");
                    System.out.print("请输入订餐人姓名：");
                    dfoot.setName(scanner.next());
                    /*循环打印菜单*/
                    System.out.println("序号"+"\t"+"菜名"+"\t"+"\t"+"单价");
                    for (int i=0;i<menu.length;i++){
                        Menu me=menu[i];
                        System.out.println(me.getId()+"\t"+me.getClName()+"\t"+me.getClPrice());
                    }
                    System.out.println("请选择您要点的菜品编号：");
                    int index= scanner.nextInt();
                    /*用来拿到具体菜的对象*/
                    Menu cun=menu[index-1];

                    dfoot.setcName(cun.getClName());
                    System.out.println("请输入您需要的份数：");
                    dfoot.setNum(scanner.nextInt());
                    System.out.println("请输入送餐地址：");
                    dfoot.setAdress(scanner.next());
                    System.out.println("请输入送餐时间：");
                    dfoot.setTime(scanner.nextInt());
                    /*总价*/
                    dfoot.setConPrice(dfoot.getNum()*cun.getClPrice());
                    System.out.println("订餐成功");
                    System.out.println("--------以下是您的订餐信息--------");;
                    System.out.println("您订的是："+dfoot.getcName()+" "+dfoot.getNum()+"份");
                    System.out.println("送达时间是："+dfoot.getTime()+"点");
                    System.out.println("餐费是："+dfoot.getConPrice());

                    //用于程序保存 每一次 订单
                    for (int i=0;i<hu.length;i++){
                        Dfoot df=  hu[i];
                        if(df == null){
                            hu[i]=dfoot;
                            break;
                        }else{
                            continue;
                        }
                    }
                    break;
                case 2:
                    //展示订单信息的对象
                    System.out.println("*****查看餐袋*****");
                    Dfoot[] df= clMenus.getDfNum();
                    for (int i=0;i<df.length;i++){
                        Dfoot showDf=df[i];
                        if (showDf!=null){
                            int num12 =showDf.getNum()-4;
                            System.out.println("序号"+"\t"+"订餐人"+"\t"+"餐品信息"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t"+"总金额"+"\t"+"订单状态");
                            System.out.println(num12+"\t"+showDf.getName()+"\t"+showDf.getcName()+"\t"+showDf.getTime()+"\t"+"\t"+showDf.getAdress()+"\t"+"\t"+showDf.getConPrice()+"\t"+"\t"+showDf.getStart());
                        }else {
                            break;
                        }
                    }
                    break;
                case 3:
                    System.out.println("*****签收订单*****");
                    Dfoot[] df1=clMenus.getDfNum();
                    for (int i=0;i<df1.length;i++){
                        Dfoot showDf = df1[i];
                        if(showDf != null){
                            int num11 = showDf.getNum()-4;
                            System.out.println("订单序号"+num11);
                            System.out.println("订餐人"+showDf.getName()+"菜品信息："+showDf.getcName()+"\t"+"签收状态："+showDf.getStart()+"\t");
                        }else{
                            System.out.println("请选择要签收的订单号：");
                            int index1=scanner.nextInt();
                            Dfoot doof= hu[index1-1];
                            if(doof==null){
                                System.out.println("无此订单");
                                break;
                            }
                            doof.setStart(1);
                            System.out.println("订单已签收");
                            System.out.println("订餐人"+doof.getName()+"菜品信息："+doof.getcName()+"\t"+"签收状态："+doof.getStart()+"\t");
                            break;
                        }
                    }
                    break;
                case 4:
                    //删除订单
                    System.out.println("*****删除订单*****");
                    System.out.println("请选择需要删除的订单序号：");
                    int ind =scanner.nextInt();
                    Dfoot[] df2=clMenus.getDfNum();
                    for (int i=0;i<df2.length;i++){
                        Dfoot dfod=    df2[ind-1];
                        if(dfod==null){
                            System.out.println("此订单不存在");
                            break;
                        }else{
                            df2[i] = null;
                            System.out.println("删除成功");
                            break;
                        }
                    }
                    break;
                case 5:
                    //我要点赞
                    System.out.println("*****我要点赞*****");
                    Dfoot[] df3=clMenus.getDfNum();
                    for (int i=0;i<df3.length;i++){
                        Dfoot dfod=df3[i];
                        if(dfod==null){
                            break;
                        }else{
                            System.out.println("订餐人"+dfod.getName()+"菜品信息："+dfod.getcName()+"\t"+"签收状态："+dfod.getStart()+"\t");
                        }
                    }
                    System.out.println("请输入需要点赞的订单：");
                    int inde4= scanner.nextInt();
                    Dfoot fdd = hu[inde4-1];
                    if(fdd==null){
                        System.out.println("此订单不存在");
                        break;
                    }else{
                        goodLike.setGname(fdd.getName());
                        goodLike.setGclName(fdd.getcName());
                        goodLike.setGnum(fdd.getNum());
                        goodLike.setCount(goodLike.getCount()+1);
                        System.out.println("点赞成功");
                    }
                    break;
                case 6:
                    whinum++;
                    System.out.println("退出成功");
                default:
                    break;
            }

        }while (whinum==0);

    }
}
